package com.tianzeculture.stagebao.activity.message.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tianzeculture.stagebao.R;

import java.util.List;

/**
 * Created by Administrator on 2018/7/11 0011.
 */

public class ChatMessageAdapter extends BaseAdapter {
    Context context;
    List<ChatMessage> chatMessages;

    public ChatMessageAdapter(Context context, List<ChatMessage> chatMessages) {
        this.context = context;
        this.chatMessages = chatMessages;
    }

    @Override
    public int getCount() {
        return chatMessages.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_chat_message, null);
            holder.tvTitle = view.findViewById(R.id.tvTitle);
            holder.tvCompany = view.findViewById(R.id.tvCompany);
            holder.tvContent = view.findViewById(R.id.tvContent);
            holder.tvTime = view.findViewById(R.id.tvTime);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        setData(holder, i);
        return view;
    }

    private void setData(ViewHolder holder, int i) {
        holder.tvTitle.setText(chatMessages.get(i).getTitle());
        holder.tvCompany.setText(chatMessages.get(i).getCompany());
        holder.tvContent.setText(chatMessages.get(i).getContent());
        holder.tvTime.setText(chatMessages.get(i).getTime());
    }

    class ViewHolder {
        TextView tvTitle;
        TextView tvCompany;
        TextView tvContent;
        TextView tvTime;
    }
}
